package com.ljj.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.ljj.entity.Question;

import com.ljj.mapper.QuestionMapper;
import com.ljj.service.IQuestionService;

import com.ljj.utli.Result;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liujiju
 * @since 2021-11-19
 */
@CrossOrigin
@RestController
@RequestMapping("/question")
public class QuestionController {

	@Autowired
	IQuestionService iq;
	@Autowired
	QuestionMapper m;

	/**
	 * 全查
	 * 
	 * @param d
	 * @return
	 */
	@RequestMapping("/qlist")
	public Object qlist(Question e) {
		

		List<Question> list = iq.qlist(e);
		
		
		e.setLimit(null);
		e.setPage(null);
		List<Question> list1 = iq.qlist(e);
		return new Result(0, "", list, list1.size());


	}

	/**
	 * 添加
	 * 
	 * @param c
	 * @return
	 */
	@RequestMapping("/qadd")
	public Object qadd(Question q) {
		
		if (m.insert(q) > 0) {
			return new Result(0, "添加成功");
		} else {
			return new Result(1, "添加失败");
		}
	}

	/**
	 * 修改
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping("/qupdate")
	public Object qupdate(Question d) {
		int i = m.updateById(d);
		System.out.println(i+"1111");
		if ( i> 0) {
			return new Result(0, "修改成功");
		} else {
			return new Result(1, "修改失败");
		}

	}

	/**
	 * 删除
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping("/qdetele")
	public Object qdetele(Question d) {
		if (m.deleteById(d) > 0) {
			return new Result(0, "删除成功");
		} else {
			return new Result(1, "删除失败");
		}

	}

}
